home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvtools
/
demos
/
citydemo
/
c4i_dsp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-08
|
16KB
|
521 lines
#ifndef lint
static char SccsId[]= "@(#)c4i_dsp.c V1.24 4/13/95";
#endif
/*------------------------------------------------------------------
| file name -- c4i_dsp.c
|
| functions Description
| --------- -----------
| InitDisplays Initializes the SCREEN and DRAWPORTS
| TermDisplays Cleans up the SCREEN, DRAWPORTS and DISPLAY_LIST
|
| OverlayDisplay Overlay the view.
| RemoveDisplay Deletes the overlayed view.
|
| Get_Drawport Returns the previously or newly created drawport.
|
| preload_views Preloads all views... (base and overlays)
| create_drawport Creates the drawport and adds it to the table
| next_display Adds a display to the list.
| create_display_list Create a DisplayList for NEXT/PREV.
| del_display_list_item Delete a display from the DisplayList.
| destroy_display_list Destroys the DisplayList.
|
|-----------------------------------------------------------------*/
#include "std.h"
#include "dvstd.h"
#include "dvGR.h"
#include "VOstd.h"
#include "Tfundecl.h"
#include "c4i_vars.h"
#include "GRfundecl.h"
#include "VOfundecl.h"
#include "VTfundecl.h"
#include "c4i_fundecl.h"
#define NEW_LIST (char)0
#define ADD_TO_LIST (char)1
#define DELETE_FROM_LIST (char)2
extern FLOAT Intro1; /* For controlling introduction view... */
/***************** Begin Function Declarations *************/
LOCAL void preload_views V_P_((void));
LOCAL DRAWPORT create_drawport V_P_((OBJECT screen, char *viewname,
BOOLPARAM stretch,
RECTANGLE *vvp, RECTANGLE *wvp));
LOCAL DRAWPORT next_display V_P_((char *view_name));
LOCAL DISPLAY_LIST *create_display_list V_P_((void));
LOCAL void del_display_list_item V_P_((DISPLAY_LIST *display_item));
LOCAL void destroy_display_list V_P_((DISPLAY_LIST **display_info));
/***************** End Function Declarations *************/
CHAR *VIstrclone (); /* Internal function: allocates & copies a string */
/*-----------------------------------------------------------------
|
| InitDisplays
| Performs the initialization needed for the display.
|
| A SCREEN is opened using DVDEVICE and other attributes.
|
| create_drawport() is called to create a drawport for each
| display area. create_drawport will be called each time a
| a new views is needed by the display manager.
*/
void
InitDisplays V_P_ ((void))
{
DRAWPORT control_dp;
OBJECT screen;
/* Create view and drawport tables needed from display management */
ViewTable = VTstsizecreate ("View Names and VIEWs", (VTSTCOMPAREFUNPTR)NULL,
VTABLE_LEN);
DpTable = VTstsizecreate ("View Names and DRAWPORTs",(VTSTCOMPAREFUNPTR)NULL,
DPTABLE_LEN);
/* Open the MAIN window */
screen = OpenWindow (MAIN_WINDOW);
EXIT_IF_INVALID (screen, NO_DEVICE);
/* Draw the main Map */
(VOID) create_drawport (DVscreen[MAIN_WINDOW], MAP_VIEW,
PreldView[0].CreateStretch,
DEFAULT_SIZE, DEFAULT_PORTION);
ActiveDrawport = next_display (MAP_VIEW);
EXIT_IF_INVALID (ActiveDrawport, NO_MAP_VIEW);
TdpDraw (ActiveDrawport);
/* Open the CONTROL window */
screen = OpenWindow (CONTROL_WINDOW);
EXIT_IF_INVALID (screen, NO_DEVICE);
control_dp = Get_Drawport (CONTROL_VIEW,
DVscreen[CONTROL_WINDOW], NO_STRETCH,
DEFAULT_SIZE, DEFAULT_PORTION);
EXIT_IF_INVALID (control_dp, NO_CONTROL_VIEW);
(VOID) TdpDraw (control_dp);
/* Set the active screen to the main window */
(VOID) TscSetCurrentScreen (DVscreen[MAIN_WINDOW]);
ActiveScreenIndex = MAIN_WINDOW;
/* Preload all the views */
preload_views ();
/* Intialize information for zooming and panning. */
InitZoomInfo ();
ZoomeD = 0; /* indicates we start in an unzoomed state */
/* Create pop-up drawports for the MAIN_WINDOW */
CreatePopupDps ();
/* Now that we are ready, reset the cursors */
TscSetCurrentScreen (DVscreen[MAIN_WINDOW]);
(VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
TscSetCurrentScreen (DVscreen[CONTROL_WINDOW]);
(VOID) GRset (V_ACTIVE_CURSOR, V_END_OF_LIST);
}
/*-----------------------------------------------------------------
|
| OverlayDisplay
| Tries to overlay a view to the current display. The
| named view is merged to the existing drawing.
|
*/
void
OverlayDisplay (view_name, dsl_merge_required)
char *view_name;
int dsl_merge_required;
{
VIEW overlay_view, main_view;
OBJECT overlay_drawing, obj_dq;
INT i, num_objs;
DATASOURCELIST main_dsl;
overlay_view = Get_View (view_name, ADD);
if (overlay_view)
{
/* Get the overlay drawing and the active view */
overlay_drawing = TviGetDrawing (overlay_view);
main_view = TdpGetView (ActiveDrawport);
/* Merge the overlay into the active view */
(VOID) TviMergeDrawing (main_view, overlay_drawing);
if (dsl_merge_required)
{
main_dsl = TviGetDataSourceList (main_view);
(VOID) TviMergeAddDataSources (overlay_view, main_dsl, DS_NAMEMATCH);
}
/* Draw the objects in the overlay view */
obj_dq = VOdrGetObjectDeque (overlay_drawing);
num_objs = VOdqSize (obj_dq);
for (i = 1; i <= num_objs; i++)
(VOID) TdpDrawObject (ActiveDrawport, VOdqGetEntry (obj_dq, i));
}
}
/*-----------------------------------------------------------------
|
| RemoveDisplay
| Tries to delete the named view from the current display. The
| named view is excised from the existing drawing.
|
*/
void
RemoveDisplay (view_name)
char *view_name;
{
VIEW overlay_view, main_view;
OBJECT overlay_drawing, obj_dq, obj;
INT i, num_objs;
RECTANGLE bounding_box, scr_offset, scr_box;
BOOLPARAM obj_is_visible;
CHAR *obj_name;
overlay_view = Get_View (view_name, ADD);
if (overlay_view)
{
/* Get the overlay drawing and the active view */
overlay_drawing = TviGetDrawing (overlay_view);
main_view = TdpGetView (ActiveDrawport);
/* Delete the overlay from the active view */
num_objs = TviExciseDrawing (main_view, overlay_drawing);
if (num_objs != 0)
{
/* Erase the overlay view */
obj_dq = VOdrGetObjectDeque (overlay_drawing);
num_objs = VOdqSize (obj_dq);
for (i = num_objs; i >= 1; i--)
{
obj = VOdqGetEntry (obj_dq, i);
obj_name = TdrGetObjectName (overlay_drawing, obj);
obj_is_visible = YES;
if (obj_name && *obj_name == INVISIBLE)
obj_is_visible = NO;
/* If we don't have an input object and the object IS visible
| restore the screen area, below the erased object */
if (obj_is_visible)
{
if (VOobType (obj) == OT_INPUT)
(VOID) TdpEraseObject (ActiveDrawport, obj);
else
{
/* Erasing an object destroys box info, so get it before erasing */
(VOID) VOobBox (obj, &bounding_box, &scr_offset);
(VOID) TdpWorldToScreen (ActiveDrawport,
&bounding_box.ll, &scr_box.ll);
(VOID) TdpWorldToScreen (ActiveDrawport,
&bounding_box.ur, &scr_box.ur);
scr_box.ll.x += scr_offset.ll.x;
scr_box.ll.y += scr_offset.ll.y;
scr_box.ur.x += scr_offset.ur.x;
scr_box.ur.y += scr_offset.ur.y;
(VOID) TdpEraseObject (ActiveDrawport, obj);
(VOID) TdpRedraw (ActiveDrawport, &scr_box, NO);
}
}
}
}
}
}
/*-----------------------------------------------------------------
|
| preload_views
| The function Pre-Loads the views....of the MAINWINDOW
*/
LOCAL void
preload_views V_P_ ((void))
{
INT i;
/* For all the preload views... load the view, create a drawport, add the
| drawport to the symbol table. NOTE: we start at index =1 because
| the top view is already loaded and visible.
*/
for (i = 1; i < NUM_VU_PRELOAD; i++)
{
(VOID) create_drawport (DVscreen[MAIN_WINDOW], PreldView[i].name,
PreldView[i].CreateStretch,
DEFAULT_SIZE, DEFAULT_PORTION);
}
}
/*-----------------------------------------------------------------
|
| create_drawport
| The function loads the view (viewname) and creates a drawport
| in the (screen) using the (vvp) and (wvp) to determine how to
| display the view.
|
| The drawport is added to the symbol tables for easy access by the
| display manager routines. Drawports are referenced by their view
| name.
|
| We call SetupButton() to setup event handling for the buttons
| embedded in the views.
|
| We call RebindData() for all the dynamic objects. This will
| see if the variable is being controlled by the application and
| rebind it if necessary.
|
*/
LOCAL DRAWPORT
create_drawport (screen, viewname, stretch, vvp, wvp)
OBJECT screen;
char *viewname;
BOOLPARAM stretch;
RECTANGLE *vvp;
RECTANGLE *wvp;
{
VIEW view;
OBJECT drawing, color;
DRAWPORT drawport = NULL;
/* Load the view */
view = TviLoad (viewname);
if (view)
{
/* Create the Drawport */
if (stretch)
drawport = TdpCreateStretch (screen, view, vvp, wvp);
else
drawport = TdpCreate (screen, view, vvp, wvp);
/* Add the drawport to the table */
(VOID) VTstsninsert (DpTable, VIstrclone (viewname), (INT *) drawport);
/* Setup the callbacks for the buttons */
SetupButtons (view); /* found in c4i_events.c */
/* Rebind the dyanmic object's variables to real-time data */
RebindData (view); /* found in c4i_rebind.c */
/* Set the off drawing color to match the drawing's background
| color. This will help the Zooming/Panning of the drawing
| look better */
if (S_STRCMP (viewname, MAP_VIEW) == 0)
{
drawing = TviGetDrawing (view);
color = VOdrBackcolor (drawing, (OBJECT) DONT_SET_THE_VALUE);
(VOID) VOdrOffcolor (color);
}
}
return drawport;
}
/*-----------------------------------------------------------------
|
| Get_Drawport
| Returns the drawport associated with the view_name. If the
| drawport doesn't exist, it creates one using create_drawport().
*/
DRAWPORT
Get_Drawport (view_name, screen, stretch, vvp, wvp)
char *view_name;
OBJECT screen;
BOOLPARAM stretch;
RECTANGLE *vvp;
RECTANGLE *wvp;
{
SYMNODE key;
/* See if the drawport is already in the Drawport Table */
key = VTstkeyfind (DpTable, view_name);
if (key)
return (DRAWPORT) VTsnvalue (key);
else
return create_drawport (screen, view_name, stretch, vvp, wvp);
}
/*-----------------------------------------------------------------
|
| next_display
| Tries to add a display to the DisplayList. If the view can't
| be displayed, returns DV_FAILURE, else DV_SUCCESS.
|
| NOTE:
| In this application, there is only one map to select. This
| DisplayList management algorithm is more useful for cases where
| there are more than one map (or view) from which to choose.
| This application is therefore expandable through the addition of
| more maps (views).
|
|
*/
LOCAL DRAWPORT
next_display (view_name)
char *view_name;
{
INT i;
DISPLAY_LIST *prev_display;
DRAWPORT dp;
/* Get the drawport associated with the view */
dp = Get_Drawport (view_name, DVscreen[MAIN_WINDOW], NO_STRETCH,
DEFAULT_SIZE, DEFAULT_PORTION);
if (dp)
{
/* If the list doesn't exist yet, create it.
|
| Make the current list top the previous display. Then,
| make the new display the list top. */
if (!DisplayList)
{
prev_display = create_display_list ();
prev_display->drawport = ActiveDrawport;
prev_display->zoomed = ZoomeD;
}
else
prev_display = DisplayList;
DisplayList = create_display_list ();
DisplayList->drawport = dp;
DisplayList->prev = prev_display;
for (i = 0; i < 4; i++)
DisplayList->overlays[i] = NO;
DisplayList->zoomed = ZoomeD;
/*init POPUP_VIEWLIST structure. */
for (i = 0; i < NUM_POPUP_DP; i++)
DisplayList->PopupDp[i] = NULL;
}
return (dp);
}
/*-----------------------------------------------------------------
|
| create_display_list - Allocates and initializes a DISPLAY_LIST.
*/
LOCAL DISPLAY_LIST *create_display_list
V_P_ ((void))
{
DISPLAY_LIST *display_info;
display_info = (DISPLAY_LIST *) S_ALLOC ((LONG) sizeof (DISPLAY_LIST));
display_info->drawport = (DRAWPORT) NULL;
display_info->prev = (DISPLAY_LIST *) NULL;
return display_info;
}
/*-----------------------------------------------------------------
|
| del_display_list_item - Frees a DISPLAY_LIST item.
*/
LOCAL void
del_display_list_item (display_item)
DISPLAY_LIST *display_item;
{
(VOID) S_FREE ((CHAR *) display_item);
}
/*-----------------------------------------------------------------
|
| destroy_display_list - Destroys the DISPLAY_LIST by freeing each item.
*/
LOCAL void
destroy_display_list (display_info)
DISPLAY_LIST **display_info;
{
DISPLAY_LIST *info, *prev;
info = *display_info;
while (info)
{
prev = info->prev;
del_display_list_item (info);
info = prev;
}
*display_info = NULL;
}
/*-----------------------------------------------------------------
|
| TermDisplays
| Performs the termination and clean up needed for the display
| components. This balances InitDisplays().
|
| The Drawport and View Tables are "traversed" to clean up
| the views and drawports. We also clean up the table as we go.
| The AreaCoords used to define drawport areas are "freed". The
| display manager's DisplayList is destroyed. Finally, the screen
| is erased and closed.
*/
void TermDisplays
V_P_ ((void))
{
INT i;
CHAR *viewname;
SYMNODE node;
VIEW view;
DRAWPORT dp;
/* Destroy the display drawports */
while (VTstlen (DpTable) > 0)
{
node = VTstsnget (DpTable, 0);
viewname = VTsnkey (node);
S_FREE (viewname);
dp = (DRAWPORT) VTsnvalue (node);
view = TdpGetView (dp);
(VOID) TdpDestroy (dp);
(VOID) TviDestroy (view);
dp = (DRAWPORT) NULL;
VTstsnremove (DpTable, node);
}
VTstdestroy (DpTable);
/* Destroy the overlay views */
while (VTstlen (ViewTable) > 0)
{
node = VTstsnget (ViewTable, 0);
viewname = VTsnkey (node);
S_FREE (viewname);
(VOID) TviDestroy ((VIEW) VTsnvalue (node));
VTstsnremove (ViewTable, node);
}
VTstdestroy (ViewTable);
/* Destroy the Calculating Drawports */
view = TdpGetView (CalculatingDp[OF_UNZOOMED_VIEW]);
(VOID) TdpDestroy (CalculatingDp[OF_UNZOOMED_VIEW]);
(VOID) TviDestroy (view);
view = TdpGetView (CalculatingDp[OF_ZOOMED_VIEW]);
(VOID) TdpDestroy (CalculatingDp[OF_ZOOMED_VIEW]);
(VOID) TviDestroy (view);
/* Destroy the Display List */
destroy_display_list (&DisplayList);
/* Destroy, Erase and Close the Windows */
for (i = 0; i < NUM_WINDOWS; i++)
CleanupWindow (i);
}
/* END TERMDISPLAYS */